# celery_task/main.py
import os
import sys
import time
import logging
import traceback

from celery import Celery
from ronglian_sms_sdk import SmsSDK


# base_dir = os.path.abspath(os.path.join(os.path.abspath(os.path.dirname(__file__)), "../../../"))
# sys.path.append(base_dir)
# 定义celery实例, 需要的参数, 1, 实例名, 2, 任务发布位置, 3, 结果保存位置

celery_app = Celery('mycelery',
                    broker='redis://101.42.224.35:6379/14',  # 任务存放的地方
                    backend='redis://101.42.224.35:6379/15',  # 结果存放的地方
                    impoerts=('celery_task', 'common/utils'))


accId = '8aaf07087f77bf96017fd54021082f71'
accToken = 'fcc9d94e2c324d32a93081fe8323c959'
appId = '8aaf07087f77bf96017fd54021ff2f78'


@celery_app.task(name='celery_task.main.add')
def phone_code(mobile, code):
    logging.info('phone_code:{}'.format(locals()))
    resp = 0
    try:
        pass
        # sdk = SmsSDK(accId, accToken, appId)
        # datas = (code, '5')
        # resp = sdk.sendMessage('1', mobile, datas)
    except:
        error = traceback.format_exc()
        logging.error('phone_code error:{}'.format(error))
    return resp

